<template>
	<!--库存状态表页面-->
	<view class="wrapper" :style="{height:wrapperHeight +'px'}">
		<!--<view class="title-padding"></view>-->
		<!-- <view class="headerGd">
			<view class="header">
				<button class="back" @tap="back()"></button>
				库存状况表
				<button class="filter" @tap="filter()"></button>
			</view>
		</view> -->
		<view class="container" :style="{height: containerHeight + 'px'}">
			<view class="curstom">
				<!-- <view class="changeList" @tap="">

				</view> -->
				<!-- <view class="cuIcon-calendar"></view> -->
				<view class="filterTime">
					<text>商品名:{{curstomName}}</text>
					<text>条码:{{BarCode}}</text>
				</view>
			</view>
			<view class="orderList" :style="{height: orderListHeight + 'px'}" v-show="isList">
				<view class="orderNav" :style="{width:tdAllWidth+'px'}"  @tap="changeWidth()">
					<text :style="{width:tdWidth[0]+'px'}">
						序号
					</text>
					<text :style="{width:tdWidth[1]+'px'}">
						图片
					</text>
					<text :style="{width:tdWidth[2]+'px'}">
						仓库
					</text>
					<text :style="{width:tdWidth[3]+'px'}">
						商品名称
					</text>
					<text :style="{width:tdWidth[4]+'px'}">
						编号
					</text>
					<text :style="{width:tdWidth[5]+'px'}">
						规格
					</text>
					<text :style="{width:tdWidth[6]+'px'}" @tap.stop.prevent="paixu1(1)">
						库存数量
						<label class="text-blue text-xl" :class="paixu01?'cuIcon-triangledownfill':'cuIcon-triangleupfill'"></label>
					</text>
					<text :style="{width:tdWidth[7]+'px'}" @tap.stop.prevent="paixu1(2)">
						成本价
						<label class="text-blue text-xl" :class="paixu02?'cuIcon-triangledownfill':'cuIcon-triangleupfill'"></label>
					</text>
					<text :style="{width:tdWidth[8]+'px'}" @tap.stop.prevent="paixu1(3)">
						成本金额
						<label class="text-blue text-xl" :class="paixu03?'cuIcon-triangledownfill':'cuIcon-triangleupfill'"></label>
					</text>
				</view>
				<view class="orderLi" :style="{height:orderLiHeight +'px',width:tdAllWidth+'px'}">
					<view class="orderItem" v-for="(item,index) in orderList" :key="index" @tap="GetGoodDetail(item.GoodsID,item.Storeid)">
						<view :style="{width:tdWidth[0]+'px'}">{{index+1}}</view>
						<!-- <view @tap.stop="showBigImg(true,item.Goods_Image_Path1)" :style="{width:tdWidth[1]+'px'}">
							<image :src="item.Goods_Image_Path1" mode="aspectFit"></image>
						</view> -->
						<view class="bg-img"  @tap.stop="ViewImage" :data-src="item.Goods_Image_Path1" :style="{width:tdWidth[1]+'px'}">
							<image :src="item.Goods_Image_Path1" mode="aspectFit"></image>
						</view>
						<view :style="{width:tdWidth[2]+'px'}">{{item.StoreName}}</view>
						<view :style="{width:tdWidth[3]+'px'}">{{item.GoodsName}}</view>
						<view :style="{width:tdWidth[4]+'px'}">{{item.GoodsCode}}</view>
						<view :style="{width:tdWidth[5]+'px'}">{{item.Spec}}</view>
						<view :style="{width:tdWidth[6]+'px'}">{{item.Qty}}</view>
						<view :style="{width:tdWidth[7]+'px'}">{{item.Price}}</view>
						<view :style="{width:tdWidth[8]+'px'}">{{item.Total}}</view>
					</view>
				</view>
				<view class="allPrice" :style="{width:tdAllWidth+'px'}">
					<text :style="{width:tdWidth[0]+'px'}">
						小计
					</text>
					<text :style="{width:tdWidth[1]+'px'}">
					</text>
					<text :style="{width:tdWidth[2]+'px'}">
					</text>
					<text :style="{width:tdWidth[3]+'px'}">
					</text>
					<text :style="{width:tdWidth[4]+'px'}">
					</text>
					<text :style="{width:tdWidth[5]+'px'}">
					</text>
					<text :style="{width:tdWidth[6]+'px'}">
						{{kcsl}}
					</text>
					<text :style="{width:tdWidth[7]+'px'}">
						{{Math.round(cbjg * 10000) / 10000}}
					</text>
					<text :style="{width:tdWidth[8]+'px'}">
						{{cbje}}
					</text>
				</view>
			</view>
			<view class="orderLookAllList" :style="{height: orderListHeight + 'px'}" v-show="!isList">
				<view class="orderLookItem" v-for="(item,index) in orderList" :style="{ display:(nowRote === index) ? 'table':'block'}"
				 :key="index">
					<view @tap="GetGoodDetail(item.GoodsID,item.Storeid)">
						<text>{{index+1}}</text>
						<text>商品名称:{{item.GoodsName}}</text>
						<text>仓库:{{item.StoreName}}</text>
						<text>编号:{{item.GoodsCode}}</text>
						<text>规格:{{item.Spec}}</text>
						<text>库存数量:{{item.Qty}}</text>
						<text>成本价:{{item.Price}}</text>
						<text>成本金额:{{item.Total}}</text>
					</view>
					<!-- <button class="lookMoreInfo" :style="{ transform :(nowRote == index)  ? 'rotate(180deg)':'rotate(0deg)'}" @tap="lookMore(index)"></button> -->
					<button class="lookMoreInfo"  @tap="lookMore(index)">
						{{nowRote == index?'收起':'展开'}}
					</button>
				</view>
			</view>
			<!-- <view class="lookBig" v-show="isShowBigImg" @tap="showBigImg(false,'')">
				<image :src="nowBigImg" mode="widthFix"></image>
			</view> -->
		</view>
		<view class="cu-modal" :class="showChange?'show':'hide'">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">设置表格列宽度</view>
					<view class="action" @tap="hideChaneg">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">
					<view class="padding-xl-item" v-for="(item,index) in tdHeaderList" :key="item.name">
						<text>{{item.name}}:</text><input v-model="tdWidthList[index]" />
					</view>
				</view>
				<view class="cu-bar bg-white justify-end">
					<view class="action">
						<button class="cu-btn bg-grey float-left" @tap="hideChaneg">取消</button>
						<button class="cu-btn stop margin-left" @tap="sureSetting">确定</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import * as Api from '@/syApis/syBb/apis.js'
	export default {
		onLoad(options) {
			if (options.type == 0) {
				this.isBillProcess = false;
			} else {
				this.isBillProcess = true;
			}
			// 获取表格框的宽度
			let tbWidList = uni.getStorageSync("StatusWidList", "");
			// console.log(OrderList);
			if (tbWidList != "") {
				this.tdWidthList = JSON.parse(tbWidList);
				this.tdWidth = JSON.parse(tbWidList);
			}
			var $this = this;
			uni.getSystemInfo({
				success(res) {
					$this.wrapperHeight = res.windowHeight;
					$this.containerHeight = res.windowHeight - 50;
					$this.orderListHeight = res.windowHeight - 50;
					$this.orderLiHeight = res.windowHeight - 50 - 80;
				}
			});
			let date = new Date();
			this.startTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
			this.endTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
			this.getCgOrder();
			
		},
		watch: {
			//统计数量
			orderList(oldval, newval) {
				var cbje = 0;
				var cbjg = 0
				var kcsl = 0;
				var _this = this;
				this.orderList.forEach(item => {
					cbje += parseFloat(item.Total);
					cbjg += parseFloat(item.Price)
					kcsl += parseFloat(item.Qty);
				});
				this.kcsl = kcsl;
				this.cbjg = cbjg;
				this.cbje = cbje;
			}
		},
		computed: {
			tdAllWidth() {
				var tdAllWidth = 0;
				this.tdWidth.forEach(item => {
					tdAllWidth += parseFloat(item);
				});
				tdAllWidth += this.tdWidth.length - 1;
				return tdAllWidth;
			}
		},
		onShow() {
			this.$eventHub.$off('fire');
		},
		methods: {
			ViewImage(e) {
				console.log(e)
				var current = e.currentTarget.dataset.src
				uni.previewImage({
					current: current,
					urls:[current] 
				});
			},
			paixu1(selectIndex) {
				var len = this.orderList.length;
				var arr = this.orderList
				console.log(selectIndex)
				// switch (selectIndex) {
				// case 1:
				if (selectIndex == 1) {
					if (this.paixu01 == false) {
						this.paixu01 = true
						for (var i = 0; i < len; i++) {
							for (var j = 0; j < len - 1 - i; j++) {
								if (parseFloat(arr[j].Qty) > parseFloat(arr[j + 1].Qty)) { //相邻元素两两对比
									var temp = arr[j + 1];
									//元素交换
									arr[j + 1] = arr[j];
									arr[j] = temp;
								}
							}
						}
					} else {
						this.paixu01 = false
						for (var i = 0; i < len; i++) {
							for (var j = 0; j < len - 1 - i; j++) {
								if (parseFloat(arr[j].Qty) < parseFloat(arr[j + 1].Qty) ) { //相邻元素两两对比
									var temp = arr[j];
									//元素交换
									arr[j] = arr[j + 1];
									arr[j + 1] = temp;
								}
							}
						}
					}
					return arr;
				} else if (selectIndex == 2) {
					if (this.paixu02 == false) {
						this.paixu02 = true
						for (var i = 0; i < len; i++) {
							for (var j = 0; j < len - 1 - i; j++) {
								if (parseFloat(arr[j].Price) > parseFloat(arr[j + 1].Price)) { //相邻元素两两对比
									var temp = arr[j + 1];
									//元素交换
									arr[j + 1] = arr[j];
									arr[j] = temp;
								}
							}
						}
					} else {
						this.paixu02 = false
						for (var i = 0; i < len; i++) {
							for (var j = 0; j < len - 1 - i; j++) {
								if (parseFloat(arr[j].Price) < parseFloat(arr[j + 1].Price)) { //相邻元素两两对比
									var temp = arr[j];
									//元素交换
									arr[j] = arr[j + 1];
									arr[j + 1] = temp;
								}
							}
						}
					}
					return arr;
				} else if (selectIndex == 3) {
					if (this.paixu03 == false) {
						this.paixu03 = true
						for (var i = 0; i < len; i++) {
							for (var j = 0; j < len - 1 - i; j++) {
								if (parseFloat(arr[j].Total) > parseFloat(arr[j + 1].Total)) { //相邻元素两两对比
									var temp = arr[j + 1];
									//元素交换
									arr[j + 1] = arr[j];
									arr[j] = temp;
								}
							}
						}
					} else {
						this.paixu03 = false
						for (var i = 0; i < len; i++) {
							for (var j = 0; j < len - 1 - i; j++) {
								if (parseFloat(arr[j].Total) < parseFloat(arr[j + 1].Total)) { //相邻元素两两对比
									var temp = arr[j];
									//元素交换
									arr[j] = arr[j + 1];
									arr[j + 1] = temp;
								}
							}
						}
					}
					return arr;
				}
			},
			//修改宽度
			changeWidth() {
				this.showChange = true;
			},
			hideChaneg() {
				this.showChange = false;
				let tempList = [];
				this.tdWidth.forEach((item,index)=>{
					tempList.push(item);
				})
				this.tdWidthList = tempList;
				// uni.setStorageSync("tbWidList",JSON.stringify(tempList));
				// this.tdWidthList = this.tdWidth;
			},
			sureSetting() {
				let tempList = [];
				this.tdWidthList.forEach((item,index)=>{
					tempList.push(item);
				})
				this.tdWidth = tempList;
				uni.setStorageSync("StatusWidList",JSON.stringify(tempList));
				this.showChange = false;
			},
			//返回上一页
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			//明细
			GetGoodDetail(GoodsID, Storeid) {
				uni.navigateTo({
					url: './StatusProcessDetail?GoodsID=' + GoodsID + "&StoreID=" + Storeid
				})
			},
// 			showBigImg(state, path) {
// 				uni.showLoading({
// 					title: "加载中"
// 				})
// 				var _this = this;
// 				setTimeout(function() {
// 					_this.isShowBigImg = state;
// 					_this.nowBigImg = path;
// 					uni.hideLoading();
// 				}, 100);
// 
// 			},
			//跳转到筛选条件页
			// filter() {
			// 	this.AddListen();
			// 	uni.navigateTo({
			// 		url: './StatusProcessFilter'
			// 	})
			// },
			// #ifndef MP
			onNavigationBarButtonTap(e) {
				const index = e.index;
				if (index === 0) {
					this.AddListen();
					uni.navigateTo({
						url: './StatusProcessFilter'
					})
				}else{
					this.changeListAl();
				}
			},
			// #endif
			AddListen() {
				var _this = this;
				this.$eventHub.$on('fire', function(data) {
					_this.curstomName = data.GoodsName == "" ? "全部商品" : data.GoodsName;
					_this.BarCode = data.BarCode == "" ? "" : "条码:" + data.BarCode;
					_this.getCgOrder(data);
					_this.$eventHub.$off('fire');
				});
			},
			//获取采购订单
			getCgOrder: function(filter) {
				let data = {};
				if (filter == undefined) {
					data = data;
				} else {
					data = filter;
				}
				var _this = this;
				Api.GetInventoryStatus(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {

						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							let responseData = res.data.ResultMsg;
							for (let item in responseData) {
								responseData[item].Goods_Image_Path1 = Api.setImageUrl(responseData[item].Goods_Image_Path1);
							}
							if(res.data.ResultMsg.length==0){
								Api.showTip("查无数据");
							}
							_this.orderList = responseData;
						}
					} else {
						Api.showTip("服务器开小差了");
					}
				});

			},
			lookMore: function(index) {
				this.nowRote = this.nowRote == index ? "-1" : index;
			},
			changeListAl: function() {
				this.isList = !this.isList;
			}
		},
		data() {
			return {
				paixu01: false,
				paixu02: false,
				paixu03: false,
				orderList: [],
				containerHeight: 100,
				wrapperHeight: 600,
				orderListHeight: 100,
				orderLiHeight: 100,
				isList: false,
				startTime: "",
				endTime: "",
				curstomName: "全部商品",
				nowRote: -1,
				//是否经营历程
				isBillProcess: false,
				BarCode: "全部条码",
				// isShowBigImg: false,
				// nowBigImg: "",
				// xjList: [{
				// 	name: "小计"
				// }, {
				// 	name: ""
				// }, {
				// 	name: ""
				// }, {
				// 	name: ""
				// }, {
				// 	name: ""
				// }, {
				// 	name: ""
				// }, {
				// 	name: ""
				// }, {
				// 	name: ""
				// }, {
				// 	name: ""
				// }],
				kcsl: "",
				cbjg: "",
				cbje: "",
				showChange: false,
				list: [{
						name: 0,
						"openAndClose": "",
						"lookMoreClass": ""
					},
					{
						name: 0,
						"openAndClose": "",
						"lookMoreClass": ""
					}, {
						name: 0,
						"openAndClose": "",
						"lookMoreClass": ""
					}
				],
				//td宽度列表
				tdWidth: [125, 125, 125, 125, 125, 125, 125, 125, 150],
				tdWidthList: [125, 125, 125, 125, 125, 125, 125, 125, 150],
				//tb表头
				tdHeaderList: [{
						name: "序号"
					},
					{
						name: "图片"
					}, {
						name: "仓库"
					}, {
						name: "商品名称"
					}, {
						name: "编号"
					}, {
						name: "规格"
					}, {
						name: "库存数量"
					}, {
						name: "成本价"
					}, {
						name: "成本金额"
					}
				]

			}
		}
	}
</script>

<style lang="scss">
	@import url('../../style/changecolum.scss');
	@import '@/static/bbCss/bb.scss';
	// $bb-bg-color:rgba(124, 170, 216, 1);

	// /*图标的大小*/
	// $iconWidth:20px;
	// $iconHeight:20px;
	// $iconBackSize:20px;

	// .title-padding {
	// 	height: var(--status-bar-height);
	// 	background: $bb-bg-color;
	// 	box-sizing: content-box;
	// }

	// page {
	// 	width: 100%;
	// 	height: 100%;
	// 	padding-bottom: 0px;
	// }

	// .wrapper {
	// 	width: 100%;
	// 	height: 100%;
	// 	display: flex;
	// 	flex-direction: column;
	// 	overflow: hidden;
	// }

	// button::after {
	// 	border: none;
	// 	padding: 0px;
	// }

	// .headerGd {
	// 	width: 100%;
	// 	height: 50px;
	// 	line-height: 50px;
	// 	background: $bb-bg-color;
	// 	display: table;

	// 	.header {
	// 		position: relative;
	// 		text-align: center;
	// 		font-size: 16px;
	// 		color: #FFF;

	// 		.back {
	// 			width: $iconWidth;
	// 			height: $iconHeight;
	// 			background: url(../../static/back.png) no-repeat;
	// 			position: absolute;
	// 			left: 10px;
	// 			top: 15px;
	// 			background-size: $iconBackSize;
	// 		}

	// 		.filter {
	// 			width: $iconWidth;
	// 			height: $iconHeight;
	// 			position: absolute;
	// 			right: 10px;
	// 			top: 15px;
	// 			background: url(../../static/cg/filter.png);
	// 		}
	// 	}
	// }

	// .container {
	// 	font-size: 14px;

	// 	.curstom {
	// 		width: 100%;
	// 		height: 50px;
	// 		line-height: 50px;
	// 		display: flex;
	// 		padding-left: 10px;
	// 		padding-right: 10px;
	// 		box-sizing: border-box;
	// 		background: rgba(124, 170, 216, 1);
	// 		box-sizing: border-box;
	// 		color: #FFF;

	// 		.curstomName {
	// 			flex: 1;
	// 			text-align: center;
	// 		}

	// 		.filterTime {
	// 			flex: 4;
	// 			text-align: center;
	// 			// display: flex;
	// 			// flex-direction: column;
	// 			white-space: nowrap;
	// 			text-overflow: ellipsis;
	// 			overflow: hidden;
	// 			text {
	// 				// flex: 1;
	// 				line-height: 25px;
	// 				height: 25px;
	// 				display:block ;
	// 				white-space: nowrap;
	// 				text-overflow: ellipsis;
	// 				overflow: hidden;
	// 				box-sizing: border-box;
	// 				padding-left: 2px;
	// 				padding-bottom: 2px;
	// 				text-align: left;
	// 			}
	// 		}

	// 		.changeList {
	// 			width: 30px;
	// 			height: 30px;
	// 			background: url(../../static/changeIcon.png) no-repeat;
	// 			background-size: 100%;
	// 			margin-top: 15px;
	// 		}
	// 	}

	// 	//表格单据
	// 	.orderList {
	// 		width: 100%;
	// 		overflow: auto;
	// 		box-sizing: border-box;

	// 		text {
	// 			float: left;
	// 			text-align: center;
	// 			box-sizing: border-box;
	// 			height: 40px;
	// 			line-height: 40px;
	// 			border-right: 1px solid #CCC;
	// 			white-space: nowrap;
	// 			text-overflow: ellipsis;
	// 			overflow: hidden;

	// 			&:last-child {
	// 				border: none;
	// 			}
	// 		}

	// 		.orderNav {
	// 			height: 40px;
	// 			line-height: 40px;
	// 			box-sizing: border-box;
	// 			overflow: hidden;
	// 			border-top: 1px solid #CCC;
	// 			border-left: 1px solid #FFF;
	// 			background: #FFF;

	// 		}

	// 		.orderLi {

	// 			background: #ebebeb;
	// 			overflow: auto;

	// 			.orderItem {
	// 				height: 40px;
	// 				line-height: 40px;
	// 				width: 100%;
	// 				border: 1px solid #ebebeb;
	// 				box-sizing: border-box;
	// 				display: table;
	// 				border-bottom: 1px solid #CCCCCC;

	// 				view {
	// 					display: inline-block;
	// 					height: 100%;
	// 					line-height: 40px;
	// 					float: left;
	// 					text-align: center;
	// 					border-right: 1px solid #CCC;
	// 					box-sizing: border-box;
	// 					padding-top: 5upx;
	// 					padding-bottom: 5upx;
	// 					white-space: nowrap;
	// 					text-overflow: ellipsis;
	// 					overflow: hidden;

	// 					image {
	// 						width: 60px;
	// 						margin: auto;
	// 						display: table;
	// 					}

	// 					&:last-child {
	// 						border: none;
	// 					}

	// 				}
	// 			}
	// 		}

	// 		.allPrice {
	// 			@extend .orderNav;
	// 			background: rgba(124, 170, 216, 1);
	// 			color: #FFF;
	// 		}
	// 	}

	// 	//列表单据
	// 	.orderLookAllList {
	// 		width: 100%;
	// 		background: #ebebeb;
	// 		box-sizing: border-box;
	// 		padding: 30upx;
	// 		box-sizing: border-box;
	// 		overflow: auto;

	// 		.orderLookItem {
	// 			width: 100%;
	// 			height: 220upx;
	// 			overflow: hidden;
	// 			position: relative;
	// 			border-radius: 20upx;
	// 			background: #FFF;
	// 			box-sizing: border-box;
	// 			padding-left: 30upx;
	// 			padding-right: 100upx;
	// 			padding-top: 5upx;
	// 			padding-bottom: 5upx;
	// 			margin-bottom: 20upx;
	// 		}

	// 		.lookMoreInfo {
	// 			width: $iconWidth;
	// 			height: $iconHeight;
	// 			background: url(../../static/pull.png) no-repeat;
	// 			position: absolute;
	// 			bottom: 10upx;
	// 			right: 10upx;
	// 			padding: 0upx;
	// 			background-size: 100% 100%;
	// 			transition: height 2s;
	// 		}

	// 		text {
	// 			display: block;
	// 			font-size: 30upx;

	// 			&:nth-child(1) {
	// 				position: absolute;
	// 				top: 10upx;
	// 				right: 10upx;
	// 				width: $iconWidth;
	// 				height: $iconHeight;
	// 				border-radius: 10upx;
	// 				text-align: center;
	// 				display: table;
	// 				color: #000;
	// 				line-height: $iconHeight;
	// 				padding: 5upx;
	// 			}

	// 			&:nth-child(n+2) {
	// 				height: 55upx;
	// 				line-height: 55upx;
	// 				display: table;
	// 			}
	// 		}

	// 		.lookMoreClass {
	// 			display: table;

	// 		}

	// 		.openAndClose {
	// 			transform: rotate(180deg);
	// 		}
	// 	}

	// }

	// //查看大图
	// .lookBig {
	// 	position: fixed;
	// 	width: 100%;
	// 	height: 100%;
	// 	overflow: auto;
	// 	top: 0;
	// 	left: 0;
	// 	background: rgba(0, 0, 0, .3);

	// 	image {
	// 		width: 70%;
	// 		margin: auto;
	// 		margin-top: 10%;
	// 	}
	// }
	// .padding-xl {
	// 	overflow: auto;
	// 	max-height: 400px;
	// }
	
	// .padding-xl-item {
	// 	display: flex;
	// }
	
	// .padding-xl-item text {
	// 	min-width: 70px;
	// 	height: 40px;
	// 	line-height: 40px;
	// 	text-align: right;
	// 	padding-right: 10px;
	// 	box-sizing: border-box;
	// 	font-size: 15px;
	// }
	
	// .padding-xl-item input {
	// 	flex: 1;
	// 	border: 1px solid #CCC;
	// 	height: 30px;
	// 	line-height: 30px;
	// 	margin-top: 5px;
	// }
	
	// .stop {
	// 	padding-left: 12px;
	// 	padding-right: 12px;
	// 	font-size: 14px;
	// 	background: rgba(124, 170, 216, 1);
	// 	color: #FFF;
	// 	box-sizing: border-box;
	// 	margin-left: 40px;
	// }
</style>
